﻿
@{
    ViewBag.Title = "用户首页";
    Layout = "~/Views/Shared/_Layout_Content.cshtml";
}
@section styles
{
    <link href="/Content/css/plugins/jqgrid/ui.jqgrid.css" rel="stylesheet" />
}

<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>用户管理</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="form-group">
                <button id="btnAdd" type="button" class="btn btn-primary " onclick="addModel()"><i class="fa fa-plus"></i>&nbsp;添加</button>
                <button id="btnEdit" type="button" class="btn btn-info " onclick="editModel()"><i class="fa fa-pencil"></i> 编辑</button>
                <button id="btnDel" type="button" class="btn btn-danger " onclick="delData()">
                    <i class="fa fa-remove"></i>&nbsp;&nbsp;<span class="bold">删除</span>
                </button>
                <button id="btnSetRole" type="button" class="btn btn-info "><i class="fa fa-user"></i> 角色授权</button>
                <button id="btnResetPwd" class="btn btn-warning"><i class="fa fa-undo"></i> 重置密码</button>
            </div>

            <div class="form-group">
                <div class="input-group">
                    <input id="txtSearchKey" type="text" class="input form-control" placeholder="搜索关键字" />
                    <span class="input-group-btn">
                        <button id="btnSearch" class="btn btn btn-primary" type="button"> <i class="fa fa-search"></i> 搜索</button>
                    </span>
                </div>
            </div>

            <div class="jqGrid_wrapper">
                <table id="table_list"></table>
                <div id="pager_list"></div>
            </div>
        </div>
    </div>
</div>

@section scripts
{
    @Scripts.Render("~/content/js/list")
    <script>
        function addModel() {
            $("#btnAdd").button("loading");
            window.location.href = "@Url.Action("Add")";
        }

        function editModel() { //编辑
            var row = JucheapGrid.GetData();
            if (row != null) {
                $("#btnEdit").button("loading");
                window.location.href = "@Url.Action("Edit")/" + row.Id;
            } else {
                parent.layer.alert("请选择要编辑的数据");
            }
        }

        function delData() { //删除
            XPage.DelData("@Url.Action("Delete")");
        }

        function searchData() { //搜索
            var json = {
                keywords: $("#txtSearchKey").val()
            };
            XPage.Search(json);
        }

        $(document).ready(function() {
            var config = {
                title: '用户列表',
                url: '@Url.Action("GetListWithPager")',
                colNames: ['主键', '登录名', '真实姓名', '部门', '邮箱', '注册时间'],
                colModel: [
                    { name: 'Id', index: 'Id', width: 60, key: true, hidden: true },
                    { name: 'LoginName', index: 'LoginName', width: 60 },
                    { name: 'RealName', index: 'RealName', width: 60 },
                    { name: 'DepartmentName', index: 'DepartmentName', width: 100 },
                    { name: 'Email', index: 'Email', width: 60 },
                    {
                        name: 'CreateDateTime',
                        index: 'CreateDateTime',
                        width: 60,
                        formatter: function(cellValue, options, rowObject) {
                            return cellValue.getDate();
                        }
                    }
                ]
            };
            JucheapGrid.Load(config);
            $("#btnSearch").bind("click", searchData);
            $("#btnSetRole").bind("click", function() {
                var row = JucheapGrid.GetData();
                if (row != null) {
                    //弹出即全屏
                    var layerIndex = parent.layer.open({
                        title: "用户角色授权",
                        type: 2,
                        content: '@Url.Action("Authen")/' + row.Id + "?username=" + row.LoginName,
                        area: ['800px', '600px'],
                        maxmin: true
                    });
                    parent.layer.full(layerIndex);
                } else {
                    parent.layer.alert("请选择要授权的用户");
                }
            });
            $("#btnResetPwd").bind("click", function () {
                var row = JucheapGrid.GetData();
                if (row != null) {
                    $(this).button("loading");
                    window.location.href = "@Url.Action("ResetPwd")/" + row.Id;
                } else {
                    parent.layer.alert("请选择要重置密码的用户");
                }
            });

        });
    </script>
}
